{% extends "base.html" %}

{% block content %}
<section id="addlist">
    <div class="row">
        <div class="col-md-12">
            <ol class="breadcrumb" style="margin-top:6px;">
                <li>添加未关联的电影，共{{ movie_count }}部</li>
            </ol>
        </div>
        <div class="col-md-12 convertlist">
            {% for v in page_data %}
                <div class="media">
                    <h4 class="media-heading" style="color: aliceblue;">{{ v.name }}<input name="cutmovie" type="checkbox" value="{{v.id}}" style="float: right;" /></h4>
                </div>
            {% end %}
            <h4 class="media-heading" style="color: aliceblue;">
                <input class="btn btn btn-success btn-block" id="convert-movie" name="" onclick="convertmovie()" style="width:10%;float: right;" type="buttom" value="合并">
            </h4>
            <script type="text/javascript" src="{{ static_url('base/js/jquery.min.js') }}"></script>
            <script type="text/javascript">
                function convertmovie(obj){
                    event.preventDefault();
                    obj = document.getElementsByName("cutmovie");
                    check_val = [];
                    for (k in obj) {
                        if (obj[k].checked)
                            check_val.push(obj[k].value);
                    }
                    // alert(check_val);
                    $.ajax({
                        type: "POST",
                        url: "/convert",
                        data: {movies:check_val},
                        dataType: 'json',
                        success: function(result){
                            if (result.code == 0){
                                for (k in obj) {
                                    if (obj[k].checked)
                                        $(obj[k]).parent().parent().remove();
                                }
                            }else{
                                alert(result.msg);
                                // console.log(result.msg);
                            }
                        },
                        error: function(result){
                            // console.log(result.msg);
                        }
                    });
                };
                $(document).ready(function() {
                    var targetElement = $('input[name="area"]',$('#search'));
                    var parent = targetElement.parent();
                    var newElement = '<input type="text"  name="convert" value="1" hidden>';
                    parent.append(newElement);
                })
            </script>
        </div>
        <div class="col-md-12 text-center">
            <nav aria-label="Page navigation">
            </nav>
        </div>
    </div>
</section>
<script type="text/javascript">

</script>
{% end %}